﻿package plugin.specialActivity.game
{
    import com.core.*;
    import com.sh.game.util.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.specialActivity.*;
    import plugin.store.*;
    import uiresource.specialActivity.*;
    import view.message.*;
    import view.mornExtends.*;

    public class LibaoGame extends LibaoUI implements IPage
    {
        private var _pageMsg:Object;
        private var _libaoArr:Array;

        public function LibaoGame(param1:Object)
        {
            this._pageMsg = param1;
            this.initEvent();
            return;
        }// end function

        private function initEvent() : void
        {
            return;
        }// end function

        public function refresh() : void
        {
            var _loc_2:Object = null;
            var _loc_3:Array = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_1:* = ModelProxy.getValue("data", "storeInfo");
            if (!_loc_1)
            {
                StoreSender._1getStoreInfo();
            }
            if (this._libaoArr == null)
            {
                this._libaoArr = [];
                _loc_2 = ConfigDictionary.data.activitygoal;
                _loc_3 = _loc_2[this._pageMsg.id];
                _loc_4 = ConfigDictionary.data.storeNew;
                _loc_5 = ConfigDictionary.data.item;
                for each (_loc_6 in _loc_3)
                {
                    
                    _loc_7 = _loc_4[_loc_6.reward];
                    _loc_8 = _loc_5[_loc_7.itemid];
                    this._libaoArr.push({storeMsg:_loc_7, itemMsg:_loc_8});
                }
            }
            list.array = this._libaoArr;
            list.renderHandler = new Handler(this.libaoRender);
            return;
        }// end function

        private function libaoRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Label = null;
            var _loc_5:FlashItem = null;
            var _loc_6:Label = null;
            var _loc_7:Label = null;
            var _loc_8:Label = null;
            var _loc_9:Button = null;
            if (param2 < list.length)
            {
                _loc_3 = param1.dataSource;
                _loc_4 = param1.getChildByName("txt_name") as Label;
                _loc_4.text = _loc_3.itemMsg.name;
                _loc_5 = param1.getChildByName("fi_item") as FlashItem;
                _loc_5.data = _loc_3.itemMsg;
                _loc_6 = param1.getChildByName("txt_desc") as Label;
                _loc_6.text = _loc_3.itemMsg.tips1;
                _loc_7 = param1.getChildByName("txt_price") as Label;
                _loc_7.text = "原价：" + (_loc_3.storeMsg.price ? (_loc_3.storeMsg.price + "元宝") : ("商城无出售"));
                _loc_8 = param1.getChildByName("txt_nowprice") as Label;
                _loc_8.text = "公测价：" + _loc_3.storeMsg.nowprice + "元宝";
                _loc_9 = param1.getChildByName("btn_goumai") as Button;
                _loc_9.clickHandler = new Handler(this.doGm, [_loc_3.storeMsg.id, _loc_3.storeMsg.nowprice, _loc_3.storeMsg.limitbuy, _loc_3.storeMsg.alllimitbuy]);
            }
            return;
        }// end function

        private function doGm(param1:int, param2:int, param3:String, param4:String) : void
        {
            var buyArr:Array;
            var buyCount:int;
            var id:* = param1;
            var nowprice:* = param2;
            var limitBuy:* = param3;
            var allLimitBuy:* = param4;
            if (txt_countdown.text == "活动剩余时间：活动已结束")
            {
                WarningManager.show(170);
                return;
            }
            if (limitBuy)
            {
                buyArr = limitBuy.split("#");
                buyCount = this.getBuyCount(id, "buyNum");
                switch(int(buyArr[0]))
                {
                    case 1:
                    {
                        if (buyArr[1] == buyCount)
                        {
                            WarningManager.show(132, [buyArr[1], buyCount, buyArr[1] - buyCount]);
                            return;
                        }
                        break;
                    }
                    case 2:
                    {
                        if (buyArr[1] == buyCount)
                        {
                            WarningManager.show(167, [buyArr[1], buyCount, buyArr[1] - buyCount]);
                            return;
                        }
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            Alert2.show("是否花费 " + MColor.getHMTL(nowprice + "元宝", 6) + "购买礼包" + " ", "消费提示", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    if (UserData.getBagData("money") < nowprice)
                    {
                        WarningManager.show(13);
                    }
                    else
                    {
                        StoreSender._4buy(id, nowprice, 1);
                    }
                }
                return;
            }// end function
            );
            return;
        }// end function

        public function getBuyCount(param1:int, param2:String) : int
        {
            var _loc_4:Object = null;
            var _loc_3:* = ModelProxy.getValue("data", "storeInfo");
            for each (_loc_4 in _loc_3)
            {
                
                if (_loc_4.storeId == param1)
                {
                    return _loc_4[param2];
                }
            }
            return 0;
        }// end function

        public function update(param1:int, param2:Object) : void
        {
            switch(param1)
            {
                case ActivityPublic.UPDATETIME:
                {
                    txt_countdown.text = String(param2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
